﻿

using System;
using System.Collections.Generic;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Linq;
using Tong;
using JModel;


public partial class aspnet_testPargrameDir_site_Member_Admin_XiaoXiangb : System.Web.UI.Page
{
    public string str = "";
    /// <summary>
    /// 當前顯示的id
    /// </summary>
    string id = "1";

    /// <summary>
    /// 用於顯示資料
    /// </summary>
    public Tong.TongUse TextData = new Tong.TongUse();

    /// <summary>
    /// 系统安装绝对路径
    /// </summary>
    public string Abs_Path = TongUse.SysPath;
    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable MyDt = new DataTable();

    public string ho = "";

    /// <summary>
    /// 站点通用方法类
    /// </summary>
    public Tong.ThisSiteUse.SiteTong TextThisSite = new Tong.ThisSiteUse.SiteTong();


    //得到传入的栏目ID
    public String CloumnID = "1";

    /// <summary>
    /// 顯示當前欄目的簡介
    /// </summary>
    public string str1 = "";
    /// <summary>
    /// 資料表
    /// </summary>
    DataTable NewDt = new DataTable();
    /// <summary>
    /// 用于分頁的對像
    /// </summary>
    Tong.Fy.FenYe FY = new Tong.Fy.FenYe();
    /// <summary>
    /// 
    /// </summary>
    public string sud = "";

    /// <summary>
    /// 標題
    /// </summary>
    public string title = "";
    /// <summary>
    /// 表名
    /// </summary>
    public string tab = "Sys_WangZhanDeTue3aae";
    /// <summary>
    /// 学生实体
    /// </summary>
    public CX_Student stud = null;

    DBEntities db = new DBEntities();


    /// <summary>
    /// 日期
    /// </summary>
    public DateTime date = DateTime.Now;

    /// <summary>
    /// 学号
    /// </summary>
    public decimal stuid = 0;

    /// <summary>
    /// 班级
    /// </summary>
    public string classNmae = "";



    protected void Page_Load(object sender, EventArgs e)
    {

        stuid = decimal.Parse(Request.QueryString["stid"]);
        date = DateTime.Parse(Request.QueryString["d"]);
        classNmae = Request.QueryString["s"];




        if (!IsPostBack)
        {
            //用户模式
            //用户模式下对所有字段进行锁定readonly
            if (!string.IsNullOrEmpty( Request.QueryString["userModel"]))
            {
                foreach (var cont in this.爱的叮咛.Parent.Controls)
                {
                    if (cont is HtmlControl)
                    {
                        HtmlControl htmlcontrol = (HtmlControl)cont;
                        if (htmlcontrol.Disabled)
                        {
                            htmlcontrol.Disabled = false;
                        }
                        else
                        {

                            htmlcontrol.Disabled = true;
                        }
                    }
                }
            }

            #region 如果记录不存在则添加一条新记录到数据库
            CX_Xiaoxiang entity = db.CX_Xiaoxiang.Where(p => p.学号 == stuid && p.日期 == date && p.班级 == classNmae).FirstOrDefault();
            if (entity == null)
            {
                //添加新记录
                entity = new CX_Xiaoxiang()
               {
                   学号 = stuid,
                   日期 = date,
                   班级 = classNmae,
                   睡眠 = string.Empty,
               };
                //添加新记录
                db.CX_Xiaoxiang.AddObject(entity);
 

                //创建索引
                var dp = db.CX_PingYuIndex.Where(p => p.学号 == entity.学号 && p.评语日期 == entity.日期 && p.班级名称 == entity.班级).FirstOrDefault();
                if (dp == null)
                {
                    //从学生表获取姓名
                    var stentity = db.CX_Student.Where(p => p.学号 == entity.学号).FirstOrDefault();
                    if (stentity != null)
                    {
                        string stname = stentity.姓名 == null ? string.Empty : stentity.姓名;
                        db.CX_PingYuIndex.AddObject(new CX_PingYuIndex()
                        {
                            学号 = stuid,
                            评语日期 = date,
                            班级名称 = classNmae,
                            姓名 = stname

                        });
                    }
                }
            }
            else
            {
                //如果记录存在则帮定数据
                教学内容.Value = entity.教学内容;
                注意力佳.Checked = entity.注意力佳;
                参与力佳.Checked = entity.参与力佳;
                牙牙学语.Checked = entity.牙牙学语;
                好奇心.Checked = entity.好奇心;
                没有精神.Checked = entity.没有精神;
                学习情形其他.Checked = entity.学习情形其他;
                情绪良好.Checked = entity.情绪良好;
                情绪尚可.Checked = entity.情绪尚可;
                情绪心情不佳.Checked = entity.情绪心情不佳;
                今日情绪其他.Checked = entity.今日情绪其他;
                活泼健康.Checked = entity.活泼健康;
                流鼻涕.Checked = entity.流鼻涕;
                透明.Checked = entity.透明;
                黄色.Checked = entity.黄色;
                咳嗽.Checked = entity.咳嗽;
                干咳.Checked = entity.干咳;
                有痰.Checked = entity.有痰;
                发烧.Checked = entity.发烧;
                时间.Value = entity.时间;
                健康状况其他.Value = entity.健康状况其他;
                换尿布次数.Value = entity.换尿布次数;
                小便.Value = entity.小便;
                大便.Value = entity.大便;
                上午点心佳.Checked = entity.上午点心佳;
                上午点心尚可.Checked = entity.上午点心尚可;
                上午点心不佳.Checked = entity.上午点心不佳;
                上午点心挑食.Checked = entity.上午点心挑食;
                下午点心佳.Checked = entity.下午点心佳;
                下午点心尚可.Checked = entity.下午点心尚可;
                下午点心不佳.Checked = entity.下午点心不佳;
                下午点心挑食.Checked = entity.下午点心挑食;
                午餐佳.Checked = entity.午餐佳;
                午餐尚可.Checked = entity.午餐尚可;
                午餐不佳.Checked = entity.午餐不佳;
                午餐挑食.Checked = entity.午餐挑食;
                睡眠.Value = entity.睡眠;
                老师的话.Value = entity.老师的话;
                老师签名.Value = entity.老师签名;
                家长反馈.Value = entity.家长反馈;
                家长签名.Value = entity.家长签名;
                爱的叮咛.Value = entity.爱的叮咛;
                爱的叮咛签名.Value = entity.爱的叮咛签名;
            }
            db.SaveChanges();
            #endregion
        }

    }

    /// <summary>
    /// 内容状态保存时发生
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public void Page_SaveStateComplete(object sender, EventArgs e)
    {

        db.Connection.Close();
        db.Dispose();
    }
    /// <summary>
    /// 保存数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        CX_Xiaoxiang entity = db.CX_Xiaoxiang.Where(p => p.学号 == stuid && p.日期 == date && p.班级 == classNmae).FirstOrDefault();
        entity.学号 = stuid;
        entity.日期 = date;
        entity.班级 = classNmae;
        entity.教学内容 = 教学内容.Value;
        entity.注意力佳 = 注意力佳.Checked;
        entity.参与力佳 = 参与力佳.Checked;
        entity.牙牙学语 = 牙牙学语.Checked;
        entity.好奇心 = 好奇心.Checked;
        entity.没有精神 = 没有精神.Checked;
        entity.学习情形其他 = 学习情形其他.Checked;
        entity.情绪良好 = 情绪良好.Checked;
        entity.情绪尚可 = 情绪尚可.Checked;
        entity.情绪心情不佳 = 情绪心情不佳.Checked;
        entity.今日情绪其他 = 今日情绪其他.Checked;
        entity.活泼健康 = 活泼健康.Checked;
        entity.流鼻涕 = 流鼻涕.Checked;
        entity.透明 = 透明.Checked;
        entity.黄色 = 黄色.Checked;
        entity.咳嗽 = 咳嗽.Checked;
        entity.干咳 = 干咳.Checked;
        entity.有痰 = 有痰.Checked;
        entity.发烧 = 发烧.Checked;
        entity.时间 = 时间.Value;
        entity.健康状况其他 = 健康状况其他.Value;
        entity.换尿布次数 = 换尿布次数.Value;
        entity.小便 = 小便.Value;
        entity.大便 = 大便.Value;
        entity.上午点心佳 = 上午点心佳.Checked;
        entity.上午点心尚可 = 上午点心尚可.Checked;
        entity.上午点心不佳 = 上午点心不佳.Checked;
        entity.上午点心挑食 = 上午点心挑食.Checked;
        entity.下午点心佳 = 下午点心佳.Checked;
        entity.下午点心尚可 = 下午点心尚可.Checked;
        entity.下午点心不佳 = 下午点心不佳.Checked;
        entity.下午点心挑食 = 下午点心挑食.Checked;
        entity.午餐佳 = 午餐佳.Checked;
        entity.午餐尚可 = 午餐尚可.Checked;
        entity.午餐不佳 = 午餐不佳.Checked;
        entity.午餐挑食 = 午餐挑食.Checked;
        entity.睡眠 = 睡眠.Value;
        entity.老师的话 = 老师的话.Value;
        entity.老师签名 = 老师签名.Value;
        entity.家长反馈 = 家长反馈.Value;
        entity.家长签名 = 家长签名.Value;
        entity.爱的叮咛 = 爱的叮咛.Value;
        entity.爱的叮咛签名 = 爱的叮咛签名.Value;

        if (!string.IsNullOrEmpty(Request.QueryString["userModel"]))
        {
            entity.完成 = true;
        }

        //db.CX_Xiaoxiang.AddObject(entity);
        db.SaveChanges();
    }
}